# 导包
from selenium import webdriver
from selenium.webdriver.common.by import By
# 1.导入鼠标操作类
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep
driver = webdriver.Firefox()
driver.maximize_window()
# 打开测试页面
url = 'file:///C:/Users/tedu/Desktop/NSD2406/html/drop.html'
driver.get(url)

# 2.实例化鼠标操作对象
action = ActionChains(driver)

# 获取要拖拽的元素
src = driver.find_element(By.CSS_SELECTOR, '#div1')
# 获取目标元素
target = driver.find_element(By.CSS_SELECTOR, '#div2')
sleep(3)
# 3.将源元素拖拽到目标元素位置
action.drag_and_drop(src, target).perform()
sleep(3)
# 4.将元素拖拽到指定位置，按照偏移量拖拽
action.drag_and_drop_by_offset(target, 500, 300).perform()

# 关闭浏览器驱动
sleep(3)
driver.quit()